/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author BlueDeep
 */

package com.jsfcompref.model;

import javax.annotation.Resource;
//import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.WebServiceRef;
import java.util.List;
import java.util.ArrayList;
import com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl;
import javax.faces.context.FacesContext;

import webservices.*;

@ManagedBean
@SessionScoped
public class userBean {
    
    @WebServiceRef(wsdlLocation = "http://localhost:8080/ClienteWS/ClienteWS?wsdl")
    public webservices.ClienteWS_Service service;
   
    @Resource
    protected WebServiceContext context;
    
    
    private int     idd;
    private Cliente cliente;
    
    private String usr;
    private String pas;
        
    private boolean login = false;

    public String getPas() {
        return pas;
    }

    public void setPas(String pas) {
        this.pas = pas;
    }

    public String getUsr() {
        return usr;
    }

    public void setUsr(String usr) {
        this.usr = usr;
    }

    
    
    
    public boolean isLogin() {
        return login;
    }

    public void setLogin(boolean login) {
        this.login = login;
    }
    
    public userBean()
       {
             this.cliente = new Cliente();
             XMLGregorianCalendarImpl fc = new XMLGregorianCalendarImpl();
             
             fc.setDay(1);
             fc.setMonth(1);
             fc.setYear(2000);
             
             this.cliente.setFechaNacimiento(fc);
             
       }
    public int getIdd()  
       {
           return idd;
       }
    
    public void setIdd(int idd) 
       {
           this.idd=idd;
       }
    
    public Cliente getCliente() 
       {
           return cliente;
       }
    
    public void setCliente(Cliente cliente)
       {
           this.cliente = cliente;
       }
    
    public String addConfirmedUser() {
        
   //     ClienteWS port = service.getClienteWSPort();
        // agencia.util.Cliente result = port.obtenerClientePorID(idd);
          
       // cliente = port.obtenerClientePorID(idd);
               
        return "resp_consulta_usuario";
        }
    
    public String guardarCliente()
       {
          ClienteWS port = service.getClienteWSPort();   
           
          port.create(cliente) ;  
           
          this.setLogin(true);
          return "inicio";
       
       }
     
    public String actualizarCliente()
       {
          ClienteWS port = service.getClienteWSPort();   
          
          port.edit(cliente);
          
          return "inicio";
       
       }
    public String logIn()
       {
          
        ClienteWS port = service.getClienteWSPort();
        Cliente clint = port.logIn(usr, pas);
        
        if (clint != null)
        {
            this.setLogin(true);     
            this.setCliente(clint);
            return "inicio";}
        else
        {this.setLogin(false);
            return "faillogin";}
           
       }
    public String logOut()
    {
        this.setLogin(false);
        return "index";
        
    }
    
    public String getUserWelcome()
    {
    if (this.isLogin())
    {
       return ", " + this.getCliente().getNombre() + " " + this.getCliente().getApellido();
    } 
    else 
    {
        return "";
    }
    
    }
    
    }

